16. Softmax

Multi-Class Classification and Softmax

Quiz - Softmax

The Softmax Function

In the next video, we'll learn about the softmax function, which is the equivalent of the sigmoid activation function, but when the problem has 3 or more classes.

DL 18 Q Softmax V2

Softmax Quiz

What function turns every number into a positive number?

SOLUTION: exp

DL 18 S Softmax

Quiz: Coding Softmax

And now, your time to shine! Let's code the formula for the Softmax function in Python.

Start Quiz:

import numpy as np

# Write a function that takes as input a list of numbers, and returns
# the list of values given by the softmax function.
def softmax(L):
    pass
import numpy as np

def softmax(L):
    expL = np.exp(L)
    sumExpL = sum(expL)
    result = []
    for i in expL:
        result.append(i*1.0/sumExpL)
    return result
    
    # Note: The function np.divide can also be used here, as follows:
    # def softmax(L):
    #     expL = np.exp(L)
    #     return np.divide (expL, expL.sum())